package com.mgfireworks.mgplatform.mgadmin.sys;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.hn.java.summer.annotation.ParamValid;

import com.mgfireworks.mgplatform.mgadmin.constants.Constant;
import com.mgfireworks.mgplatform.mgadmin.sys.model.Dictionary;

/**
 * 
 * @author nap
 * 20161015-10:19:48
 * 字典表控制器
 */
@Controller
@RequestMapping("/sys/dictionary")
public class DictionaryController {

	@Autowired
	DictionaryService dictionaryService;
	
	/**
	 * 字典表列表
	 * @return
	 */
	@RequestMapping("/list")
	public List<Dictionary> list(Dictionary p){
		return dictionaryService.getDictionarys(p);
	}

	/**
	 * 添加字典表
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public void add(){
	}
	
	/**
	 * 提交添加字典表
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public void postAdd(@ParamValid Dictionary p){
		dictionaryService.addDictionary(p);
	}

	/**
	 * 编辑字典表
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public Dictionary edit(Dictionary p){
		return dictionaryService.getDictionary(p);
	}
	
	/**
	 * 提交编辑字典表
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public void postEdit(@ParamValid Dictionary p){
		dictionaryService.editDictionary(p);
	}
	
	/**
	 * 获取字典表
	 */
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public Dictionary get(Dictionary p){
		return dictionaryService.getDictionary(p);
	}
	
	/**
	 * 删除字典表
	 */
	@RequestMapping("/del")
	public void del(Dictionary p){
		dictionaryService.delDictionary(p);
	}
	
	/**
	 * 销售级别列表
	 * @return
	 */
	@RequestMapping("/sellLevelList")
	public List<Dictionary> sellLevelList(Dictionary p){
		p.setParentId(Constant.SELLlEVEL_PARENTID);
		return dictionaryService.getDictionarys(p);
	}
	/**
	 * 编辑销售级别
	 */
	@RequestMapping(value="/editSellLevel",method=RequestMethod.GET)
	public Dictionary editSellLevel(Dictionary p){
		return dictionaryService.getDictionary(p);
	}
	/**
	 * 提交编辑销售级别
	 */
	@RequestMapping(value="/editSellLevel",method=RequestMethod.POST)
	public void postEditSellLevel(@ParamValid Dictionary p){
		p.setParentId(Constant.SELLlEVEL_PARENTID);
		dictionaryService.editDictionary(p);
	}
	/**
	 * 提交添加销售级别
	 */
	@RequestMapping(value="/addSellLevel",method=RequestMethod.GET)
	public Dictionary addSellLevel(){
		return dictionaryService.newDictionaryId();
	}
	/**
	 * 提交添加销售级别
	 */
	@RequestMapping(value="/addSellLevel",method=RequestMethod.POST)
	public void postAddSellLevel(@ParamValid Dictionary p){
		p.setParentId(Constant.SELLlEVEL_PARENTID);
		dictionaryService.addDictionary(p);
	}
	/**
	 * 删除字典表
	 */
	@RequestMapping("/delSellLevel")
	public void delSellLevel(Dictionary p){
		dictionaryService.delDictionary(p);
	}
}